package edu.rjxy.xjdx.emps.servlet;

import com.alibaba.fastjson.JSON;
import edu.rjxy.xjdx.emps.common.JSONUtil;
import edu.rjxy.xjdx.emps.common.domain.Employee;
import edu.rjxy.xjdx.emps.common.utils.PageInfo;
import edu.rjxy.xjdx.emps.service.EmployeeService;
import edu.rjxy.xjdx.emps.service.EmployeeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/delEmp")
public class DeleteEmpServlet extends HttpServlet {
    EmployeeService employeeService = new EmployeeServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String idTxt = request.getParameter("id");
        int id = Integer.parseInt(idTxt);
        System.out.println("后台打印，浏览器发送过来的id:"+id );

        employeeService.removeEmployeeById(id);
        Map<String,Object> map=new HashMap<>();
        map.put("success",true);
        JSONUtil.printJSON(map,response);
    }
}

/*    当前页码  pageNo
    每页显示数量 pageSize  10
        总数: count     112
        页数 ：page = (int)(count/pageSize) + (count%pageSize==0?0:1)
        limit  ? ,?    (pageNo-1)*pageSize,pageSize
*/
